package sorting;

import java.util.Arrays;
import java.util.Random;

public class Insert {

	void fun(int[] a, int size, int key, int j) {
		a[size + 1] = key;
		int temp = a[size + 1];
		for (int i = size; i >= j; i--)
			a[i+1] = a[i];
		a[j] = temp;
	}

	static void compare(int[] a, int k) {
		int j;
		while ((j = k - 1) >= 0) {
			if (a[j] <= a[k])
				break;
			int temp = a[j];
			a[j] = a[k];
			a[k] = temp;
			k = j;
		}
	}

	static void sort(int[] a) {
		if (a.length <= 1)
			return;
		for (int i = 1; i < a.length; i++)
			compare(a, i);
		System.out.println(Arrays.toString(a));
	}

	public static void main(String[] args) {
		int size = 10;
		Random rand = new Random();
		int[] a = new int[size];
		for (int i = 0; i < size; i++)
			a[i] = rand.nextInt(20);
		System.out.println(Arrays.toString(a));
		sort(a);
	}
}
